home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / mpfeel.lha / MPFeel / Plurals / MP_Context.m < prev    next >
Text File  |  1992-05-29  |  3KB  |  154 lines

  1. /*
  2.  *    Plurals
  3.  *
  4.  *    Author:    S.C.Merrall
  5.  *
  6.  *    File:      MP_Context.h
  7.  *
  8.  *    Contents:    
  9.  *
  10.  *    Description:      Plurals, a new class are identified by a set of
  11.  *            processors and a pointers to objects within those
  12.  *            processors. The set of processors is described by
  13.  *            the context of a plural which is shared between
  14.  *            conformant plurals.
  15.  *
  16.  *    Change History:
  17.  *
  18.  *    Date   Name Comment
  19.  *  -------- ---- -------
  20.  *  28:06:91 SCM  Created - hacked from MP_Plural.m
  21.  *  08:04:92 SCM  Modifications to allow garbage collection - handles are
  22.  *          chained and the free flag is used by the system!
  23.  *
  24.  */
  25.  
  26. /* Include Files */
  27. /* ======= ===== */
  28.  
  29. #include <mpl.h>
  30. /*  #include "proc_pair.h"
  31.  *  #include "seq_net.h"
  32.  */
  33.  
  34. #include "constant.h"
  35.  
  36. #include <stdio.h>
  37. #include "mp_object.h"
  38. #include "mp_debug_off.h"
  39.  
  40. /* Global Variables */
  41.  
  42. object MPC_chain;    /* Head of chain of MasPar Context objects */
  43.  
  44. /* External Functions */
  45. /* ======== ========= */
  46.  
  47. #ifdef __STDC__
  48.  
  49. extern free_plural( object );
  50.  
  51. #else
  52.  
  53. extern int free_plural();
  54.  
  55. #endif
  56.  
  57.  
  58. /* Object Handling Code */
  59. /* ====== ======== ==== */
  60.  
  61. /*----------------------------------------------------------------------------*
  62.  * Function   : MPC_free
  63.  *
  64.  * Parameters : object MPC_to_be_freed:    The MP_Context object to be freed
  65.  *
  66.  * Description:    Free's an MP_Context object.
  67.  *
  68.  * Result     : int:    SUCCESS
  69.  *---------------------------------------------------------------------------*/
  70.  
  71. #ifdef __STDC__
  72.  
  73. int MPC_free( object MPC_to_be_freed )
  74.  
  75. #else
  76.  
  77. int MPC_free( MPC_to_be_freed )
  78.  
  79. object MPC_to_be_freed;
  80.  
  81. #endif
  82.  
  83. {
  84.  
  85. DBG_CALL("MPC_free");
  86. DBG_ARGS(fprintf(dbg,"MPP_to_be_freed=%lx",MPC_to_be_freed));
  87.  
  88.   OF_free(MPC_to_be_freed);
  89.   free((char *) MPC_to_be_freed);
  90.  
  91. DBG_EXIT(fprintf(dbg,"SUCCESS"));
  92.   return SUCCESS;
  93. }
  94.  
  95. /*----------------------------------------------------------------------------*
  96.  * Function   : MPC_make
  97.  *
  98.  * Parameters : none
  99.  *
  100.  * Description:    This function creates a handle for a plural Context object
  101.  *              The information in the object identifies whic set of processors
  102.  *              should be active, it contains the offset of the head of the
  103.  *              context stack so the active set can be further modified by
  104.  *              mp-if etc ..., the objects are chained in a list for GC
  105.  *        reasons.
  106.  *
  107.  * Result     : object:    The new MP_Context object
  108.  *---------------------------------------------------------------------------*/
  109.  
  110. #ifdef __STDC__
  111.  
  112. object MPC_make( int width, int height )
  113.  
  114. #else
  115.  
  116. object MPC_make( width, height )
  117.  
  118. int width;
  119. int height;
  120.  
  121. #endif
  122.  
  123. {
  124.   object MPC_new;
  125.  
  126. DBG_CALL("MPC_make");
  127. DBG_ARGS(fprintf(dbg,"width=%d,height=%d",width,height));
  128.  
  129.   MPC_new = OF_make(OC_MP_Context);     /* Allocate generic Lisplural object */
  130.  
  131.   OA_width(MPC_new) = (natural) width;
  132.   OA_height(MPC_new) = (natural) height;
  133.  
  134.   if (alloc_plural(MPC_new) == FAIL) {
  135.  
  136. DBG_FAIL(fprintf(dbg,"FAIL: Unable to allocate plural space"));
  137.     OF_destroy(MPC_new);
  138.     return FAIL;
  139.   }
  140.  
  141.   OA_next(MPC_new) = MPC_chain;         /* chain */
  142.   MPC_chain = MPC_new;
  143.  
  144. DBG_EXIT(fprintf(dbg,"%lx",MPC_new));
  145.   return MPC_new;
  146. }
  147.  
  148. struct MP_Context OC_MP_Context = {OI_MP_Context,
  149.                    MPC_free,
  150.                    MPC_make,
  151.                    0, 0, 0, 0, 0, 0};
  152.  
  153.  
  154.